//
//  ALPS_SpecialDetailTableCell.m
//  Alps
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_SpecialDetailTableCell.h"

@implementation ALPS_SpecialDetailTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        
        UIView *imgBackView = [[UIView alloc] init];
        [self.contentView addSubview:imgBackView];
        imgBackView.layer.cornerRadius = 38;
        imgBackView.backgroundColor = [UIColor whiteColor];
        [imgBackView makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.top).offset(12);
            make.left.equalTo(self.contentView.left).offset(7);
            make.width.and.height.equalTo(76);
        }];
        imgBackView.layer.borderWidth = 1;
        imgBackView.layer.borderColor = [UIColor colorWithWhite:0.818 alpha:1.000].CGColor;
        
        self.leftImgView = [[UIImageView alloc] init];
        [self.contentView addSubview:_leftImgView];
        self.leftImgView.layer.cornerRadius = 35;
        self.leftImgView.layer.masksToBounds = YES;
        
        UIImageView *playImgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 30, 30)];
        [self.leftImgView addSubview:playImgView];
        playImgView.image = [UIImage imageNamed:@"play播放"];
        playImgView.tintColor = [UIColor whiteColor];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        self.titleLabel.numberOfLines = 0;
        
        self.playCountsLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_playCountsLabel];
        self.playCountsLabel.font = [UIFont systemFontOfSize:12];
        
        self.timeLongLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_timeLongLabel];
        self.timeLongLabel.font = [UIFont systemFontOfSize:12];
    }
    return self;
}

- (void)setModel:(ALPS_SpecialDetailModel *)model
{
    [self.leftImgView sd_setImageWithURL:[NSURL URLWithString:model.coverLarge]];
    self.titleLabel.text = model.title;
    self.playCountsLabel.text = [NSString stringWithFormat:@"播放%.1f万", model.playtimes / 10000.0];
    // 计算播放时长
    NSInteger minutes = model.duration / 60;
    NSInteger second = model.duration % 60;
    self.timeLongLabel.text = [NSString stringWithFormat:@"时长%2.ld:%2.ld", minutes, second];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.leftImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(10);
        make.top.equalTo(self.contentView.top).offset(15);
        make.bottom.equalTo(self.contentView.bottom).offset(-15);
        make.width.equalTo(70);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.top).offset(15);
        make.left.equalTo(self.leftImgView.right).offset(15);
        make.right.equalTo(self.contentView.right).offset(-15);
        make.height.equalTo(45);
    }];
    
    UIImageView *playCountsImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:playCountsImgView];
    [playCountsImgView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(15);
        make.left.equalTo(self.titleLabel);
        make.bottom.equalTo(self.contentView.bottom).offset(-15);
        make.width.equalTo(10);
    }];
    playCountsImgView.image = [UIImage imageNamed:@"album_play"];
    
    [self.playCountsLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(10);
        make.left.equalTo(playCountsImgView.right).offset(3);
        make.bottom.equalTo(self.contentView.bottom).offset(-10);
        make.width.equalTo(75);
    }];
    
    UIImageView *timeLongImgView = [[UIImageView alloc] init];
    timeLongImgView.image = [UIImage imageNamed:@"歌曲持续时间"];
    [self.contentView addSubview:timeLongImgView];
    [timeLongImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.playCountsLabel.right).offset(3);
        make.top.and.bottom.and.width.equalTo(playCountsImgView);
    }];
    
    [self.timeLongLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(timeLongImgView.right).offset(3);
        make.top.and.bottom.and.width.equalTo(self.playCountsLabel);
    }];
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
